﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Public;

namespace DAL
{
    public class ProducTypeDAL
    {
        DBConnection conn = new DBConnection();
        public DataSet GetAllProductTypeCBX()
        {
            return conn.LoadDBComBox("SELECT * FROM ProductType");
        }

        public DataTable searchProType(string searchValue)
        {
            return conn.loadData("SELECT * FROM ProductType WHERE ProductType.typeName LIKE '%" + searchValue + "%'");
        }

        public int AddProductType(Public.Type type)
        {
            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@typeName"; value[0] = type.TypeName;
            return conn.Update("INSERT INTO ProductType(typeName) VALUES (@typeName)",
                                    name, value, Nparameter);
        }
        public int UpdateProductType(Public.Type type)
        {
            int Nparameter = 2;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];
            name[0] = "@typeName"; value[0] = type.TypeName;
            name[1] = "@typeId"; value[1] = type.TypeId;
            return conn.Update("UPDATE ProductType SET typeName=@typeName WHERE typeId=@typeId",
                                    name, value, Nparameter);
        }
    }
}
